package com.ljwm.controller;

import cn.hutool.core.lang.Dict;
import com.google.common.collect.Maps;
import com.ljwm.bootbase.controller.BaseController;
import com.ljwm.bootbase.dto.Result;
import com.ljwm.bootbase.security.LoginInfoHolder;
import com.ljwm.bootbase.security.SecurityKit;
import com.ljwm.model.dto.LoginForm;
import com.ljwm.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * BootBaseDemo Created by yunqisong on 2018-05-22.
 * FOR:
 */
@RequestMapping("auth")
@RestController
@Api(tags = "权限模块 API")
@SuppressWarnings("ALL")
public class AuthController extends BaseController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    @ApiOperation("登录接口")
    public Result login(LoginForm loginForm) {
        LoginInfoHolder.setLoginType("ADMIN");
        return success(userService.loginAdmin(loginForm));
    }

    @GetMapping("withAuth")
    @ApiOperation("测试需要权限接口")
    public Result withAuth() {

        return success(userService.meAdmin(SecurityKit.currentUser()));
    }

    @GetMapping("withOutAuth")
    @ApiOperation("测试不需要权限接口")
    public Result withOutAuth() {

        return success(Dict.create().set("What", "Is").set("You", "Name"));
    }


}
